#include <iostream>
// 泛型编程
template<typename T>
T add(T a,T b) //函数模板
{
    return a + b;
}

// double add(double a,double b)
// {
//     return a + b;
// }

// std::string add(std::string a,std::string b)
// {
//     return a + b;
// }
template<typename T>
void Swap(T& a,T& b)
{
    T temp = a;
    a = b;
    b = temp;
}

template<typename T>
void Sort(T *a,int size)
{
    for(int i = 0;i < size-1;i++)
    {
        for(int j = 0;j <size-i-1;j++)
        {
            if(a[j] > a[j+1])
                Swap<T>(a[j],a[j+1]);
        }
    }
}

template<typename T>
void Print(T*a,int size)
{
    for(int i = 0;i < size;i++)
    {
        std::cout<<a[i]<<" ";
    }
    std::cout<<std::endl;
}

class Student
{
public:
    Student(int id,const std::string&  name):id(id),name(name){}
    friend bool operator>(const Student& s1,const Student& s2);
    friend std::ostream& operator<<(std::ostream & os,const Student & s);

public:
    int id;
    std::string name;
};

bool operator>(const Student& s1,const Student& s2)
{
    return s1.id > s2.id;
}

std::ostream& operator<<(std::ostream & os,const Student & s)
{
    os << s.id << s.name<<std::endl;
    return os;
}

//模板的显示具体化
template<>
void Swap<Student>(Student &a,Student &b)
{
    std::string name = a.name;
    a.name = b.name;
    b.name = name;
}
int main()
{   
    // //模板的显示调用 
    // std::cout<<add<int>(1,2)<<std::endl;
    // //模板的隐示调用
    // printf("%d\n",add('\n','B'));

    // Student a[] = 
    // {
    //     {2,"zhangsan"},
    //     {1,"lisi"}
    // };
    // Sort(a,2);
    // Print(a,2);

    Student s1(1,"zhangsan");
    Student s2(2,"lisi");

    Swap(s1,s2);
    std::cout<<s1<<std::endl;
    std::cout<<s2<<std::endl;

    return 0;
}